//
//  UIImageView+Extension.swift
//  LiveTrivia
//
//  Created by Gesen on 2017/12/3.
//  Copyright © 2017年 LiveTrivia. All rights reserved.
//

import UIKit
import Kingfisher

extension KingfisherWrapper where Base: ImageView {
    
    func setCircleImage(with resource: Resource, radius: CGFloat, placeholder: Placeholder? = nil) {
        
        let size = radius * 2 * UIScreen.main.scale
        let processor = RoundCornerImageProcessor(
            cornerRadius: size * 0.5,
            targetSize: CGSize(width: size, height: size),
            roundingCorners: .all,
            backgroundColor: .clear
        )
        
        let options: [KingfisherOptionsInfoItem] = [
            .transition(.fade(0.1)),
            .targetCache(KingfisherManager.shared.cache),
            .processor(processor),
            .backgroundDecode,
            .cacheMemoryOnly
        ]
        
        setImage(with: resource, placeholder: placeholder, options: options)
    }
}
